import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_card.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/task/process_exec_entity.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/process_execution/detail/ctrl.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

/// 流程审批 - 我的审批
class ProcessExecPage extends StatelessWidget {
  ProcessExecPage({super.key});

  final ctrl = Get.put(ProcessExecListCtrl());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.Pure_gray_bg,
      appBar: CustomAppBar(
        title: Text(ctrl.tree?.treeName ?? '', style: const TextStyle(fontSize: 17)),
        showAlarmButton: false,
      ),
      body: Column(
        children: [
          AppGaps.vGap10,
          CustomSearchEnter(),
          AppGaps.vGap10,
          Expanded(
            child: GetBuilder(
              init: ctrl,
              builder: (_) {
                return ListView.builder(
                  itemBuilder: (context, index) {
                    return _buildItem(ctrl.items[index]);
                  },
                  itemCount: ctrl.items.length,
                );
              },
            ),
          ),
        ],
      ).paddingSymmetric(horizontal: 17.w),
    );
  }

  // Widget _wrapCard(Widget child) {
  //   return Container(
  //       decoration: BoxDecoration(
  //         color: Colors.white,
  //         borderRadius: BorderRadius.circular(17.w),
  //       ),
  //       margin: const EdgeInsets.all(17),
  //       padding: const EdgeInsets.all(17),
  //       child: child,
  //   ).paddingSymmetric(vertical: 7.w);
  // }

  Widget _buildItem(ProcessExecEntity item) {
    return CustomCard(
      title: item.rtemplateName,
      divider: CustomCard.builtinDividerWithPadding,
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          CustomTextWidget.getTextRowView(title: '提交人：', value: item.submitUser ?? ''),
          AppGaps.vGap6,
          CustomTextWidget.getTextRowView(title: '提交时间：', value: item.templateTime ?? ''),
          AppGaps.vGap6,
          _getApprovalButton(item),
        ],
      ),
    ).paddingOnly(bottom: 11.w);
  }

  Widget _getApprovalButton(ProcessExecEntity item) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          '操作:',
          style: TextStyle(
            fontSize: 13.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        Container(
          padding: EdgeInsets.fromLTRB(10.w, 6.w, 6.w, 6.w),
          decoration: BoxDecoration(
            color: const Color(0xFFE5E7FF),
            borderRadius: BorderRadius.circular(4.w),
          ),
          child: Row(
            children: [
              Text(
                '审核',
                style: TextStyle(
                  fontSize: 13.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xff5C6DFF),
                ),
              ),
              AppGaps.hGap2,
              SvgPicture.asset(
                AppImages.icon_right_arrow,
              ),
            ],
          ),
        ).clickOnce(() {
          Get.toNamed(
            AppRoutes.myTaskProcessApprovalDetailSign,
            arguments: item,
          );
        }),
      ],
    );
  }
}
